<template>
    <div class="ran" @transitionend="end">  
        <div class="ranimg" :style="`background-image: url(${ img });`"></div> 
        <div class="head" ref="head">
            <i class="iconfont" @click="setaudioranFlag(false)">&#xeb0b;</i>
            <h4>{{ sings[audioIndex] ? sings[audioIndex].name : '' }}</h4>
        </div>
        <div class="imgbox">
            <img :src="img" alt="">
        </div>  
        <footer>
            <div class="time">
                <div class="con">
                    <span class="btime">{{ dtime }}</span>
                    <div class="zbf">
                        <p class="schedule" :style="`width:${ perc }%;`"></p>
                        <div class="zbfp" :style="`left :${ perc }%;`"></div>
                    </div>
                    <span class="ztime" ref="ztime">{{ audioTime }}</span>
                </div>
            </div>            
            <div class="bottom" ref="bottom">
                <i class="iconfont" @click="setType" v-if="type === 0">&#xe8cc;</i>
                <i class="iconfont" @click="setType" v-if="type === 1">&#xe791;</i>
                <i class="iconfont" @click="setType" v-if="type === 2">&#xeb0d;</i>
                <i class="iconfont" @click="setindexaudio(3)">&#xe670;</i>
                <i class="iconfont" v-if="audioplay" @click="setaudioplay()">&#xe720;</i>
                <i class="iconfont" v-if="!audioplay" @click="setaudioplay()">&#xe809;</i>
                <i class="iconfont" @click="setindexaudio(1)">&#xe674;</i>
                <i class="iconfont" :class="{active: sings[audioIndex].zan}" @click="zan(sings[audioIndex])">&#xe60b;</i>
            </div>

        </footer>      
    </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
    computed: {
        ...mapState(['img', 'sings', 'audioIndex', 'audioTime', 'dtime', 'perc', 'audioranFlag', 'audioplay', 'type']),
    },
    methods: {
        ...mapMutations(['setaudioranFlag', 'setindexaudio', 'setaudioplay', 'getpraise', 'setType']),
        end(){
            if(this.audioranFlag){
                this.$refs.head.style.top = '0'
                this.$refs.bottom.style.top = '0'
            }              
        },
        zan(obj){
            obj.zan = !obj.zan
            this.getpraise(obj)
        }
    }
}
</script>

<style lang="scss" scoped>
    @keyframes ran{
        0%{
            transform: rotate(0deg);
        }
        100%{
            transform: rotate(360deg);
        }
    }
    .ran{
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 3;        
        background-color: #333;    
        transition: all 0.2s linear;    
    }
    .ranimg{
        width: 100%;
        height: 100%;
        position: absolute;
        filter: blur(20px);
        top: 0;
        left: 0;
        background-repeat: no-repeat;
        background-size: 100% 100%;
        z-index: -1;
    }
    .head{
        position: relative;
        height: 60px;
        top: -60px;
        transition: top .4s linear;
        i.iconfont{
            color: #ffcd32;
            position: absolute;
            font-size: 26px;
            left: 10px;
            top: 12px;           
        }
        h4{
            line-height: 60px;
            padding: 0 100px;
            text-align: center;
            color:  #ffcd32;
            font-size: 20px;
            font-weight: 700;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    }   
    .imgbox{
        text-align: center;
        flex: 1;
        img{
            width: 300px;
            height: 300px;
            border: 8px solid;
            border-color: rgba(255, 255, 255, .3);
            border-radius: 50%;
            margin: 0 auto;
            animation: ran 10s linear infinite;
        }
    }
    footer{
        height: 150px;
    }
    .bottom{
        height: 80px;
        display: flex;
        padding: 0 10px;
        justify-content: space-around;
        align-items: center;
        color: #ffcd32;
        position: relative;
        top: 80px;
        transition: top .4s linear;
        i.iconfont{
            font-size: 30px;
            &.active{
                color: crimson;
            }
        }
    }
    .time{
        position: relative;
        height: 50px;
    }
    .con{
        width: 100%;
        position: absolute;
        left: 0;
        top: 20px;
        padding: 0 20px;
        display: flex;
        color: #fff;
        align-items: center;
        >div{
            flex: 1;
            margin: 0 16px;
            height: 4px;
            background: #eee;
            position: relative;
            border-radius: 2px;
            p{
                position: absolute;
                left: 0;
                top: 0;
                height: 4px;
                background: crimson;
                border-radius: 2px;
            }
            div{
                width: 16px;
                height: 16px;
                border-radius: 50%;
                background: #fff;
                position: absolute;
                left: -8px;
                top: -6px;
            }
        }
        span{
            width: 40px;
            text-align: center;
        }
    }
</style>